


package yf.mall.controller;
import com.yf.request.SearchParam;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import yf.mall.dao.LotteryCountDao;
import yf.mall.enums.MallOrderOrderStatusEnum;
import yf.mall.service.MallOrderService;
import yf.mall.vo.LotteryCountNumberVo;
import yf.mall.vo.LotteryCountVo;
import yf.mall.service.LotteryCountService;
import com.yf.response.R;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 抽奖机会Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Thu Aug 20 17:10:40 CST 2020
 */
@RestController
@RequestMapping("/lottery/count")
public class LotteryCountController {
    @Autowired
    private LotteryCountService lotteryCountService;

    /**
     * 列表抽奖机会
     */
    @SysLog("查看抽奖机会")
    @RequestMapping("/list")
    @RequiresPermissions("lottery:count:list")
    public R list(@RequestBody SearchParam<LotteryCountVo> params) {
        PageHelper.startPage(params.getPage(), params.getLimit()).setOrderBy(params.getOrder());
        List<LotteryCountVo> list = lotteryCountService.findVo(params.getEntity());
        return R.ok(new PageInfo(list));
    }

    /**
 * 下载订单
 */
    @SysLog("下载订单")
    @RequestMapping("/down")
    @RequiresPermissions("lottery:count:list")
    public void down(@RequestBody SearchParam<LotteryCountVo> params, HttpServletResponse response) {
        List<LotteryCountVo> list = lotteryCountService.findVo(params.getEntity());
            lotteryCountService.downLoad(response, list);
    }


    /**
     * 查看抽奖机会
     */
    @SysLog("查看抽奖机会")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lottery:count:info")
    public R info(@PathVariable("id") Long id) {
            LotteryCountVo vo = lotteryCountService.getVo(id);

        return R.ok(vo);
    }

    /**
     * 保存抽奖机会
     */
    @SysLog("保存抽奖机会")
    @RequestMapping("/save")
    @RequiresPermissions("lottery:count:save")
    public R save(@RequestBody LotteryCountVo vo) {
            lotteryCountService.saveVo(vo);
        return R.ok(vo);
    }

    /**
     * 修改抽奖机会
     */
    @SysLog("修改抽奖机会")
    @RequestMapping("/update")
    @RequiresPermissions("lottery:count:update")
    public R update(@RequestBody LotteryCountVo vo) {
            lotteryCountService.updateVo(vo);

        return R.ok(vo);
    }

    /**
     * 删除抽奖机会
     */
    @SysLog("删除抽奖机会")
    @RequestMapping("/delete")
    @RequiresPermissions("lottery:count:delete")
    public R delete(Long[]ids) {
            lotteryCountService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有抽奖机会
     */
    @SysLog("所有抽奖机会")
    @RequestMapping("/all")
    public R all(String order) {
        PageHelper.orderBy(order!=null ? order : "id desc");
        List<LotteryCountVo> list = lotteryCountService.findVo(null);
        return R.ok(list);
    }

    /**
     * 所有enums
     */
    @SysLog("所有enums")
    @RequestMapping("/dmz/options")
    public R options() {
        HashMap<String,Object> options = new HashMap();
                                                                                                return R.ok(options);
    }




    /***********自定义开始***********/
    /**
     * 临时查看抽奖机会的方法
     * @param userId
     * @return
     */
    @RequestMapping("/dmz/getLotteryCount")
    public R getLotteryCount(Long userId){
        LotteryCountNumberVo lotteryCount = lotteryCountService.getLotteryCount(userId, MallOrderOrderStatusEnum.CANCELED.getIndex());
        return R.ok(lotteryCount);
    }

}
